package ar.edu.utn.frsf.cidisi.ginet.generation.pnml2wscdl.elementstemplate;

import org.eclipse.emf.common.util.BasicEList;
import org.eclipse.emf.common.util.EList;
import org.pnml.tools.epnk.pnmlcoremodel.Page;
import org.w3._2005._10.cdl.TChoice;
import org.w3._2005._10.cdl.TChoreography;
import org.w3._2005._10.cdl.TExtensibleElements;
import org.w3._2005._10.cdl.TInteraction;
import org.w3._2005._10.cdl.TParallel;
import org.w3._2005._10.cdl.TSequence;
import org.w3._2005._10.cdl.TWorkunit;

import ar.edu.utn.frsf.cidisi.ginet.generation.pnml2wscdl.popup.actions.WSCDLCreator;

public class WSCDLStructure {
	
	protected Page page;
	protected TChoreography choreography;
	
	protected EList<Page> getPages(Page page) {
		EList<Page> pages = new BasicEList<Page>();
		
		for (Object object : page.getObject()) {
			if( object instanceof Page){
				pages.add((Page)object);
			}
		}
		
		return pages;
	}

	protected void addTo(TExtensibleElements element1,
			TExtensibleElements element) {
		if(element1 instanceof TSequence){
			
			if(element instanceof TChoice){
				((TSequence)element1).getChoice().add((TChoice) element);
			}
			
			if(element instanceof TParallel){
				((TSequence)element1).getParallel().add((TParallel) element);
			}
			
			if(element instanceof TWorkunit){
				((TSequence)element1).getWorkunit().add((TWorkunit) element);
			}
			if(element instanceof TSequence){
				((TSequence)element1).getSequence().add((TSequence) element);
			}
			
			if(element instanceof TInteraction){
				((TSequence)element1).getInteraction().add((TInteraction) element);
			}
		}
		if(element1 instanceof TWorkunit){
			if(element instanceof TChoice){
				((TWorkunit)element1).setChoice((TChoice) element);
			}
			
			if(element instanceof TParallel){
				((TWorkunit)element1).setParallel((TParallel) element);
			}
			
			if(element instanceof TWorkunit){
				((TWorkunit)element1).setWorkunit((TWorkunit) element);
			}
			
			if(element instanceof TSequence){
				((TWorkunit)element1).setSequence((TSequence) element);
			}
			
			if(element instanceof TInteraction){
				((TWorkunit)element1).setInteraction((TInteraction) element);
			}
			
		}
	}
	
	public TExtensibleElements createWSCDLElement(){
		return null;
	}
	
	public TExtensibleElements createPackageWscdl(Page page, TChoreography choreography){
		return WSCDLCreator.createPackage(page, choreography);
	}
}
